home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / MRU.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  18.6 KB  |  651 lines

  1. //*************************************************************
  2. //  File name: mru.c
  3. //
  4. //  Description:
  5. //
  6. //      Routines for MRU support
  7. //
  8. //  Development Team:
  9. //
  10. //      Gilles Vollant (100144.2636@compuserve.com) 
  11. //
  12. //*************************************************************
  13.  
  14. #include "stdafx.h"
  15. #include <windows.h>
  16. #include <windowsx.h>
  17. #include <string.h>
  18.  
  19. #include "mru.h"
  20. // CreateMruMenu  : MRUMENU constructor
  21. // wNbLruShowInit : nb of item showed in menu
  22. // wNbLruMenuInit : nb of item stored in memory
  23. // wMaxSizeLruItemInit : size max. of filename
  24.  
  25.  
  26. //*************************************************************
  27. //
  28. //  CreateMruMenu()
  29. //
  30. //  Purpose:
  31. //
  32. //              Allocate and Initialize an MRU and return a pointer on it
  33. //
  34. //
  35. //  Parameters:
  36. //
  37. //      WORD wNbLruShowInit -      Maximum number of item displayed on menu
  38. //      WORD wNbLruMenuInit -      Maximum number of item stored in memory
  39. //      WORD wMaxSizeLruItemInit - Maximum size of an item (ie size of pathname)
  40. //      WORD wIdMruInit -          ID of the first item in the menu (default:IDMRU)
  41. //
  42. //
  43. //  Return: (LPMRUMENU)
  44. //
  45. //      Pointer on a MRUMENU structure, used by other function
  46. //
  47. //
  48. //  Comments:
  49. //      wNbLruShowInit <= wNbLruMenuInit
  50. //
  51. //
  52. //  History:    Date       Author       Comment
  53. //              09/24/94   G. Vollant   Created
  54. //
  55. //*************************************************************
  56.  
  57. LPMRUMENU CreateMruMenu (WORD wNbLruShowInit,
  58.             WORD wNbLruMenuInit,WORD wMaxSizeLruItemInit,WORD wIdMruInit)
  59. {
  60. LPMRUMENU lpMruMenu;
  61.   lpMruMenu = (LPMRUMENU)GlobalAllocPtr(GHND,sizeof(MRUMENU));
  62.  
  63.   lpMruMenu->wNbItemFill = 0;                   
  64.   lpMruMenu->wNbLruMenu = wNbLruMenuInit;             
  65.   lpMruMenu->wNbLruShow = wNbLruShowInit;
  66.   lpMruMenu->wIdMru = wIdMruInit;
  67.   lpMruMenu->wMaxSizeLruItem = wMaxSizeLruItemInit;
  68.   lpMruMenu->lpMRU = (LPSTR)GlobalAllocPtr(GHND,
  69.                       lpMruMenu->wNbLruMenu*(UINT)lpMruMenu->wMaxSizeLruItem);
  70.   if (lpMruMenu->lpMRU == NULL)
  71.      {
  72.        GlobalFreePtr(lpMruMenu);
  73.        lpMruMenu =  NULL;
  74.      }
  75.   return lpMruMenu;
  76. }
  77.  
  78. //*************************************************************
  79. //
  80. //  CreateMruMenuDefault()
  81. //
  82. //  Purpose:
  83. //
  84. //              Allocate and Initialize an MRU and return a pointer on it
  85. //              Use default parameter
  86. //
  87. //
  88. //  Parameters:
  89. //
  90. //
  91. //  Return: (LPMRUMENU)
  92. //
  93. //      Pointer on a MRUMENU structure, used by other function
  94. //
  95. //
  96. //  Comments:
  97. //
  98. //
  99. //  History:    Date       Author       Comment
  100. //              09/24/94   G. Vollant   Created
  101. //
  102. //*************************************************************
  103.  
  104. LPMRUMENU CreateMruMenuDefault()
  105. {
  106.   return CreateMruMenu (NBMRUMENUSHOW,NBMRUMENU,MAXSIZEMRUITEM,IDMRU);
  107. }
  108.  
  109.  
  110. //*************************************************************
  111. //
  112. //  DeleteMruMenu()
  113. //
  114. //  Purpose:
  115. //              Destructor :
  116. //              Clean and free a MRUMENU structure
  117. //
  118. //  Parameters:
  119. //
  120. //      LPMRUMENU lpMruMenu -      pointer on MRUMENU, allocated
  121. //             by CreateMruMenu() or CreateMruMenuDefault()
  122. //
  123. //
  124. //  Return: void
  125. //
  126. //
  127. //  Comments:
  128. //
  129. //
  130. //  History:    Date       Author       Comment
  131. //              09/24/94   G. Vollant   Created
  132. //
  133. //*************************************************************
  134. void DeleteMruMenu(LPMRUMENU lpMruMenu)
  135. {
  136.   GlobalFreePtr(lpMruMenu->lpMRU);
  137.   GlobalFreePtr(lpMruMenu);
  138. }
  139.  
  140. //*************************************************************
  141. //
  142. //  SetNbLruShow()
  143. //
  144. //  Purpose:
  145. //              Change the maximum number of item displayed on menu
  146. //
  147. //  Parameters:
  148. //      LPMRUMENU lpMruMenu -      pointer on MRUMENU
  149. //      WORD wNbLruShowInit -      Maximum number of item displayed on menu
  150. //
  151. //
  152. //  Return: void
  153. //
  154. //
  155. //  Comments:
  156. //
  157. //
  158. //  History:    Date       Author       Comment
  159. //              09/24/94   G. Vollant   Created
  160. //
  161. //*************************************************************
  162. void SetNbLruShow   (LPMRUMENU lpMruMenu,WORD wNbLruShowInit)
  163. {
  164.   lpMruMenu->wNbLruShow = min(wNbLruShowInit,lpMruMenu->wNbLruMenu);
  165. }
  166.  
  167. //*************************************************************
  168. //
  169. //  SetMenuItem()
  170. //
  171. //  Purpose:
  172. //              Set the filename of an item 
  173. //
  174. //  Parameters:
  175. //      LPMRUMENU lpMruMenu -      pointer on MRUMENU
  176. //      WORD wItem -               Number of Item to set, zero based
  177. //      LPSTR lpItem -             String, contain the filename of the item
  178. //
  179. //
  180. //  Return: (BOOL)
  181. //      TRUE  - Function run successfully
  182. //      FALSE - Function don't run successfully
  183. //
  184. //
  185. //  Comments:
  186. //      used when load .INI or reg database
  187. //
  188. //  History:    Date       Author       Comment
  189. //              09/24/94   G. Vollant   Created
  190. //
  191. //*************************************************************
  192. BOOL SetMenuItem    (LPMRUMENU lpMruMenu,WORD wItem,LPSTR lpItem)
  193. {                                      
  194.   if (wItem >= NBMRUMENU) 
  195.     return FALSE;
  196.   _fstrncpy((lpMruMenu->lpMRU) + 
  197.             ((lpMruMenu->wMaxSizeLruItem) * (UINT)wItem),
  198.             lpItem,lpMruMenu->wMaxSizeLruItem-1);
  199.   lpMruMenu->wNbItemFill = max(lpMruMenu->wNbItemFill,wItem+1);
  200.   return TRUE;
  201. }
  202.  
  203. //*************************************************************
  204. //
  205. //  GetMenuItem()
  206. //
  207. //  Purpose:
  208. //              Get the filename of an item 
  209. //
  210. //  Parameters:
  211. //      LPMRUMENU lpMruMenu -      pointer on MRUMENU
  212. //      WORD wItem -               Number of Item to set, zero based
  213. //      BOOL fIDMBased -           TRUE :  wItem is based on ID menu item
  214. //                                 FALSE : wItem is zero-based
  215. //      LPSTR lpItem -             String where the filename of the item will be
  216. //                                   stored by GetMenuItem()
  217. //      UINT  uiSize -             Size of the lpItem buffer
  218. //
  219. //
  220. //  Return: (BOOL)
  221. //      TRUE  - Function run successfully
  222. //      FALSE - Function don't run successfully
  223. //
  224. //
  225. //  Comments:
  226. //      Used for saving in .INI or reg database, or when user select
  227. //        an MRU in File menu
  228. //
  229. //  History:    Date       Author       Comment
  230. //              09/24/94   G. Vollant   Created
  231. //
  232. //*************************************************************
  233. BOOL GetMenuItem    (LPMRUMENU lpMruMenu,WORD wItem,
  234.                      BOOL fIDMBased,LPSTR lpItem,UINT uiSize)
  235. {
  236.   if (fIDMBased) 
  237.     wItem -= (lpMruMenu->wIdMru + 1);
  238.   if (wItem >= lpMruMenu->wNbItemFill) 
  239.     return FALSE;
  240.   _fstrncpy(lpItem,(lpMruMenu->lpMRU) + 
  241.                 ((lpMruMenu->wMaxSizeLruItem) * (UINT)(wItem)),uiSize);
  242.   *(lpItem+uiSize-1) = '\0';
  243.   return TRUE;
  244. }
  245.  
  246. //*************************************************************
  247. //
  248. //  AddNewItem()
  249. //
  250. //  Purpose:
  251. //              Add an item at the begin of the list
  252. //
  253. //  Parameters:
  254. //      LPMRUMENU lpMruMenu -      pointer on MRUMENU
  255. //      LPSTR lpItem -             String contain the filename to add
  256. //
  257. //  Return: (BOOL)
  258. //      TRUE  - Function run successfully
  259. //      FALSE - Function don't run successfully
  260. //
  261. //
  262. //  Comments:
  263. //      Used when used open a file (using File Open common
  264. //        dialog, Drag and drop or MRU)
  265. //
  266. //  History:    Date       Author       Comment
  267. //              09/24/94   G. Vollant   Created
  268. //
  269. //*************************************************************
  270. void AddNewItem     (LPMRUMENU lpMruMenu,LPSTR lpItem)
  271. {
  272. WORD i,j;
  273.   for (i=0;i<lpMruMenu->wNbItemFill;i++)
  274.     if (lstrcmpi(lpItem,(lpMruMenu->lpMRU) + 
  275.         ((lpMruMenu->wMaxSizeLruItem) * (UINT)i)) == 0)
  276.       {         
  277.         // Shift the other items
  278.         for (j=i;j>0;j--)
  279.          lstrcpy((lpMruMenu->lpMRU) + (lpMruMenu->wMaxSizeLruItem * (UINT)j),
  280.                  (lpMruMenu->lpMRU) + (lpMruMenu->wMaxSizeLruItem * (UINT)(j-1)));
  281.         _fstrncpy(lpMruMenu->lpMRU,lpItem,lpMruMenu->wMaxSizeLruItem-1);  
  282.         return ;
  283.       }
  284.   lpMruMenu->wNbItemFill = min(lpMruMenu->wNbItemFill+1,lpMruMenu->wNbLruMenu);
  285.   for (i=lpMruMenu->wNbItemFill-1;i>0;i--)
  286.      lstrcpy(lpMruMenu->lpMRU + (lpMruMenu->wMaxSizeLruItem * (UINT)i),
  287.              lpMruMenu->lpMRU + (lpMruMenu->wMaxSizeLruItem * (UINT)(i-1)));
  288.   _fstrncpy(lpMruMenu->lpMRU,lpItem,lpMruMenu->wMaxSizeLruItem-1);  
  289. }
  290.  
  291. //*************************************************************
  292. //
  293. //  DelMenuItem()
  294. //
  295. //  Purpose:
  296. //              Delete an item
  297. //
  298. //  Parameters:
  299. //      LPMRUMENU lpMruMenu -      pointer on MRUMENU
  300. //      WORD wItem -               Number of Item to set, zero based
  301. //      BOOL fIDMBased -           TRUE :  wItem is based on ID menu item
  302. //                                 FALSE : wItem is zero-based
  303. //
  304. //  Return: (BOOL)
  305. //      TRUE  - Function run successfully
  306. //      FALSE - Function don't run successfully
  307. //
  308. //
  309. //  Comments:
  310. //      Used when used open a file, using MRU, and when an error
  311. //         occured (by example, when file was deleted)
  312. //
  313. //  History:    Date       Author       Comment
  314. //              09/24/94   G. Vollant   Created
  315. //
  316. //*************************************************************
  317. BOOL DelMenuItem(LPMRUMENU lpMruMenu,WORD wItem,BOOL fIDMBased)
  318. WORD i;
  319.   if (fIDMBased) 
  320.     wItem -= (lpMruMenu->wIdMru + 1);
  321.   if (lpMruMenu->wNbItemFill <= wItem) 
  322.     return FALSE;
  323.   lpMruMenu->wNbItemFill--;
  324.   for (i=wItem;i<lpMruMenu->wNbItemFill;i++)
  325.      lstrcpy(lpMruMenu->lpMRU + (lpMruMenu->wMaxSizeLruItem * (UINT)i),
  326.              lpMruMenu->lpMRU + (lpMruMenu->wMaxSizeLruItem * (UINT)(i+1)));
  327.   return TRUE;
  328. }
  329.                            
  330. //*************************************************************
  331. //
  332. //  PlaceMenuMRUItem()
  333. //
  334. //  Purpose:
  335. //              Add MRU at the end of a menu
  336. //
  337. //  Parameters:
  338. //      LPMRUMENU lpMruMenu -      pointer on MRUMENU
  339. //      HMENU hMenu -              Handle of menu where MRU must be added
  340. //      UINT uiItem -              Item of menu entry where MRU must be added
  341. //
  342. //  Return: void
  343. //
  344. //
  345. //  Comments:
  346. //      Used MRU is modified, for refresh the File menu
  347. //
  348. //  History:    Date       Author       Comment
  349. //              09/24/94   G. Vollant   Created
  350. //
  351. //*************************************************************
  352. void PlaceMenuMRUItem(LPMRUMENU lpMruMenu,HMENU hMenu,UINT uiItem)
  353. {
  354. int  i;   
  355. WORD wNbShow;
  356.   if (hMenu == NULL) 
  357.     return;
  358.   // remove old MRU in menu
  359.   for (i=0;i<=(int)(lpMruMenu->wNbLruMenu);i++)
  360.     RemoveMenu(hMenu,i+lpMruMenu->wIdMru,MF_BYCOMMAND);
  361.  
  362.   if (lpMruMenu->wNbItemFill == 0) 
  363.     return;
  364.  
  365.   // If they are item, insert a separator before the files
  366.   InsertMenu(hMenu,uiItem,MF_SEPARATOR,lpMruMenu->wIdMru,NULL);
  367.  
  368.   wNbShow = min(lpMruMenu->wNbItemFill,lpMruMenu->wNbLruShow);
  369.   for (i=(int)wNbShow-1;i>=0;i--)
  370.   {
  371.   LPSTR lpTxt;
  372.     if (lpTxt = (LPSTR)GlobalAllocPtr(GHND,lpMruMenu->wMaxSizeLruItem + 20))
  373.       {
  374.         wsprintf(lpTxt,"&%lu %s",
  375.                  (DWORD)(i+1),lpMruMenu->lpMRU + (lpMruMenu->wMaxSizeLruItem*(UINT)i));
  376.         InsertMenu(hMenu,(((WORD)i)!=(wNbShow-1)) ? (lpMruMenu->wIdMru+i+2) : lpMruMenu->wIdMru,
  377.                    MF_STRING,lpMruMenu->wIdMru+i+1,lpTxt);   
  378.         GlobalFreePtr(lpTxt);
  379.       }
  380.   }
  381.  
  382. }
  383.  
  384. ///////////////////////////////////////////
  385.  
  386.  
  387.  
  388. //*************************************************************
  389. //
  390. //  SaveMruInIni()
  391. //
  392. //  Purpose:
  393. //              Save MRU in a private .INI
  394. //
  395. //  Parameters:
  396. //      LPMRUMENU lpMruMenu -      pointer on MRUMENU
  397. //      LPSTR lpszSection  -       Points to a null-terminated string containing
  398. //                                      the name of the section 
  399. //      LPSTR lpszFile -           Points to a null-terminated string that names 
  400. //                                      the initialization file. 
  401. //
  402. //  Return: (BOOL)
  403. //      TRUE  - Function run successfully
  404. //      FALSE - Function don't run successfully
  405. //
  406. //
  407. //  Comments:
  408. //      See WritePrivateProfileString API for more info on lpszSection and lpszFile
  409. //
  410. //  History:    Date       Author       Comment
  411. //              09/24/94   G. Vollant   Created
  412. //
  413. //*************************************************************
  414. BOOL SaveMruInIni(LPMRUMENU lpMruMenu,LPSTR lpszSection,LPSTR lpszFile)
  415. {
  416. LPSTR lpTxt;
  417. WORD i;
  418.  
  419.   lpTxt = (LPSTR)GlobalAllocPtr(GHND,lpMruMenu->wMaxSizeLruItem + 20);
  420.   if (lpTxt == NULL) 
  421.     return FALSE;
  422.  
  423.   for (i=0;i<lpMruMenu->wNbLruMenu;i++)
  424.     {
  425.     char szEntry[16];
  426.       wsprintf(szEntry,"File%lu",(DWORD)i+1);
  427.       if (!GetMenuItem(lpMruMenu,i,FALSE,lpTxt,lpMruMenu->wMaxSizeLruItem + 10))
  428.         *lpTxt = '\0';
  429.       WritePrivateProfileString(lpszSection,szEntry,lpTxt,lpszFile);
  430.     }
  431.   GlobalFreePtr(lpTxt);
  432.   WritePrivateProfileString(NULL,NULL,NULL,lpszFile); // flush cache 
  433.   return TRUE;
  434. }
  435.  
  436.  
  437. //*************************************************************
  438. //
  439. //  LoadMruInIni()
  440. //
  441. //  Purpose:
  442. //              Load MRU from a private .INI
  443. //
  444. //  Parameters:
  445. //      LPMRUMENU lpMruMenu -      pointer on MRUMENU
  446. //      LPSTR lpszSection  -       Points to a null-terminated string containing
  447. //                                      the name of the section 
  448. //      LPSTR lpszFile -           Points to a null-terminated string that names 
  449. //                                      the initialization file. 
  450. //
  451. //  Return: (BOOL)
  452. //      TRUE  - Function run successfully
  453. //      FALSE - Function don't run successfully
  454. //
  455. //
  456. //  Comments:
  457. //      See GetPrivateProfileString API for more info on lpszSection and lpszFile
  458. //
  459. //  History:    Date       Author       Comment
  460. //              09/24/94   G. Vollant   Created
  461. //
  462. //*************************************************************
  463. BOOL LoadMruInIni(LPMRUMENU lpMruMenu,LPSTR lpszSection,LPSTR lpszFile)
  464. {
  465. LPSTR lpTxt;
  466. WORD i;
  467.   lpTxt = (LPSTR)GlobalAllocPtr(GHND,lpMruMenu->wMaxSizeLruItem + 20);
  468.   if (lpTxt == NULL) 
  469.     return FALSE;
  470.  
  471.   for (i=0;i<lpMruMenu->wNbLruMenu;i++)
  472.     {
  473.     char szEntry[16];
  474.       
  475.       wsprintf(szEntry,"File%lu",(DWORD)i+1);
  476.       GetPrivateProfileString(lpszSection,szEntry,"",lpTxt,
  477.                               lpMruMenu->wMaxSizeLruItem + 10,lpszFile);
  478.       if (*lpTxt == '\0')
  479.         break;
  480.       SetMenuItem(lpMruMenu,i,lpTxt);
  481.     }
  482.   GlobalFreePtr(lpTxt);
  483.   return TRUE;
  484. }
  485.  
  486. #ifdef WIN32
  487.  
  488. BOOL IsWin395OrHigher(void)
  489. {
  490.   WORD wVer;
  491.  
  492.   wVer = LOWORD(GetVersion());
  493.   wVer = (((WORD)LOBYTE(wVer)) << 8) | (WORD)HIBYTE(wVer);
  494.  
  495.   return (wVer >= 0x035F);              // 5F = 95 dec
  496. }
  497.  
  498.  
  499. //*************************************************************
  500. //
  501. //  SaveMruInReg()
  502. //
  503. //  Purpose:
  504. //              Save MRU in the registry
  505. //
  506. //  Parameters:
  507. //      LPMRUMENU lpMruMenu -      pointer on MRUMENU
  508. //      LPSTR lpszKey  -           Points to a null-terminated string 
  509. //                                      specifying  the name of a key that 
  510. //                                      this function opens or creates.
  511. //
  512. //  Return: (BOOL)
  513. //      TRUE  - Function run successfully
  514. //      FALSE - Function don't run successfully
  515. //
  516. //
  517. //  Comments:
  518. //      Win32 function designed for Windows NT and Windows 95
  519. //      See RegCreateKeyEx API for more info on lpszKey
  520. //
  521. //  History:    Date       Author       Comment
  522. //              09/24/94   G. Vollant   Created
  523. //
  524. //*************************************************************
  525. BOOL SaveMruInReg(LPMRUMENU lpMruMenu,LPSTR lpszKey)
  526. {
  527. LPSTR lpTxt;
  528. WORD i;
  529. HKEY hCurKey;
  530. DWORD dwDisp;
  531.  
  532.   lpTxt = (LPSTR)GlobalAllocPtr(GHND,lpMruMenu->wMaxSizeLruItem + 20);
  533.   if (lpTxt == NULL) 
  534.     return FALSE;
  535.  
  536.   RegCreateKeyEx(HKEY_CURRENT_USER,lpszKey,0,NULL,
  537.                   REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hCurKey,&dwDisp);
  538.  
  539.   for (i=0;i<lpMruMenu->wNbLruMenu;i++)
  540.     {
  541.     char szEntry[16];
  542.       wsprintf(szEntry,"File%lu",(DWORD)i+1);
  543.       if (!GetMenuItem(lpMruMenu,i,FALSE,lpTxt,lpMruMenu->wMaxSizeLruItem + 10))
  544.         *lpTxt = '\0';
  545.       RegSetValueEx(hCurKey,szEntry,0,REG_SZ,(unsigned char*)lpTxt,lstrlen(lpTxt));
  546.     }
  547.   RegCloseKey(hCurKey);
  548.   GlobalFreePtr(lpTxt);
  549.   return TRUE;
  550. }
  551.  
  552. //*************************************************************
  553. //
  554. //  LoadMruInReg()
  555. //
  556. //  Purpose:
  557. //              Load MRU from the registry
  558. //
  559. //  Parameters:
  560. //      LPMRUMENU lpMruMenu -      pointer on MRUMENU
  561. //      LPSTR lpszKey  -           Points to a null-terminated string 
  562. //                                      specifying  the name of a key that 
  563. //                                      this function opens or creates.
  564. //
  565. //  Return: (BOOL)
  566. //      TRUE  - Function run successfully
  567. //      FALSE - Function don't run successfully
  568. //
  569. //
  570. //  Comments:
  571. //      Win32 function designed for Windows NT and Windows 95
  572. //      See RegOpenKeyEx API for more info on lpszKey
  573. //
  574. //  History:    Date       Author       Comment
  575. //              09/24/94   G. Vollant   Created
  576. //
  577. //*************************************************************
  578. BOOL LoadMruInReg(LPMRUMENU lpMruMenu,LPSTR lpszKey)
  579. {
  580. LPSTR lpTxt;
  581. WORD i;
  582. HKEY hCurKey;
  583. DWORD dwType;
  584.   lpTxt = (LPSTR)GlobalAllocPtr(GHND,lpMruMenu->wMaxSizeLruItem + 20);
  585.   if (lpTxt == NULL) 
  586.     return FALSE;
  587.  
  588.   RegOpenKeyEx(HKEY_CURRENT_USER,lpszKey,0,KEY_READ,&hCurKey);
  589.  
  590.  
  591.   for (i=0;i<lpMruMenu->wNbLruMenu;i++)
  592.     {
  593.     char szEntry[16];
  594.     DWORD dwSizeBuf;  
  595.       wsprintf(szEntry,"File%lu",(DWORD)i+1);
  596.       *lpTxt = '\0';
  597.       dwSizeBuf = lpMruMenu->wMaxSizeLruItem + 10;
  598.       RegQueryValueEx(hCurKey,szEntry,NULL,&dwType,(LPBYTE)lpTxt,&dwSizeBuf);
  599.       *(lpTxt+dwSizeBuf)='\0';
  600.       if (*lpTxt == '\0')
  601.         break;
  602.       SetMenuItem(lpMruMenu,i,lpTxt);
  603.     }
  604.   RegCloseKey(hCurKey);
  605.   GlobalFreePtr(lpTxt);
  606.   return TRUE;
  607. }
  608.  
  609.  
  610. //*************************************************************
  611. //
  612. //  GetWin32Kind()
  613. //
  614. //  Purpose:
  615. //              Get the Win32 platform
  616. //
  617. //  Parameters:
  618. //
  619. //  Return: (WIN32KIND)
  620. //      WINNT -           Run under Windows NT
  621. //      WIN32S -          Run under Windows 3.1x + Win32s
  622. //      WIN95ORGREATHER - Run under Windows 95
  623. //
  624. //
  625. //  Comments:
  626. //      Win32 function designed for Windows NT and Windows 95
  627. //      See RegOpenKeyEx API for more info on lpszKey
  628. //
  629. //  History:    Date       Author       Comment
  630. //              09/24/94   G. Vollant   Created
  631. //
  632. //*************************************************************
  633. WIN32KIND GetWin32Kind()
  634. {
  635. BOOL IsWin395OrHigher(void);
  636.  
  637.   WORD wVer;
  638.  
  639.   if ((GetVersion() & 0x80000000) == 0)
  640.     return WINNT;
  641.   wVer = LOWORD(GetVersion());
  642.   wVer = (((WORD)LOBYTE(wVer)) << 8) | (WORD)HIBYTE(wVer);
  643.  
  644.   if (wVer >= 0x035F)
  645.     return WIN95ORGREATHER;
  646.   else
  647.     return WIN32S;
  648. }
  649. #endif
  650.